from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class PermissionCreateDTO(BaseModel):
    """Permission creation data transfer object."""
    name: str = Field(..., min_length=2, max_length=100)
    code: str = Field(..., min_length=2, max_length=100)
    description: Optional[str] = None


class PermissionUpdateDTO(BaseModel):
    """Permission update data transfer object."""
    name: Optional[str] = Field(None, min_length=2, max_length=100)
    code: Optional[str] = Field(None, min_length=2, max_length=100)
    description: Optional[str] = None


class PermissionDTO(BaseModel):
    """Permission data transfer object."""
    id: UUID
    name: str
    code: str
    description: Optional[str]
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True
